/**
 ********************************************************************
 * @author roocket
 * @file    pwm.h
 * @version V0.0.0
 * @date    2024/4/26
 * @brief   This file is to indicate pwm functions. 
 * @attention Code file rules:
 * rule: file encoding use UTF8;
 * rule: max line length 120 characters;
 * rule: line separator \r\n;
 * rule: use clion auto code format tool.
 */

#ifndef _PWM_H_
#define _PWM_H_
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>

#define PWM_CONTROLLER_SYSFS_PWM_CHIPX "/sys/class/pwm/pwmchip"

/* structure for pwm controller */
struct pwm_controller
{
    unsigned char node;
    int period;
    int duty_cycle;
    char polarity[32];
    int enable;
    int which_chip;
};

/* init pwm device */
int pwm_controller_init(struct pwm_controller *pwm);

/* deinit pwm device */
int pwm_controller_deinit(struct pwm_controller *pwm);

/* start pwm */
int pwm_controller_start(int handler);

/* stop pwm */
int pwm_controller_stop(int handler);

#endif /* _PWM_H_ */
